footer.init();
header.init('疑难解答');
var pro_load_page = 2,pro_load_flag = true;
var quesList = {
	init : function(){
		app.ajax(
			'/Member/News/getting_started_list',
			{
				classid : 26,
				page :1,
				keyword : ''
			},function(res){
				if(res.code == 200){
					if(res.list.length > 0){
						app.tpl($('.pro-list'),'tpl-pro-list',res);
								echo.init();
					}else{
						$('.pro-list').html("<div class='tC promp-order' style='position:absolute;top:50%;left:15%;height:30%;width:70%;'><span class='cGrey fS15'>亲  这个页面还没有数据哦~</span></div>");
					}
				}else{
					layer.msg('网络繁忙，请稍候再试');
				}
			}
		);
	},
	loadMore :function(url,data){
		var listLoadingEmpty = '<div style="height:3rem;line-height:3rem;text-align:center;font-size:1.2rem;" class="no-more">努力加载中~<div>';
   		$('.pro-list').append(listLoadingEmpty);
		pro_load_flag = false;
		app.ajax(
			url,
			data,
			function(res){
				$('.pro-list .no-more').remove();
				if(res.code == 200){
					if(res.list.length > 0){
						app.tpladd($('.pro-list'),'tpl-pro-list',res);	
						echo.init();
						pro_load_page++;
						pro_load_flag = true;
					}else{
						var listLoadingEmpty = '<div style="height:3rem;line-height:3rem;text-align:center;font-size:1.2rem;">没有更多数据了~<div>';
						$('.pro-list').append(listLoadingEmpty);
					}
					//page++;
				}else{		
					layer.msg('网络繁忙，请稍候再试');
				}
			});	
	}
}

quesList.init();
window.onload = function(){
	if($('header').html()){
		$('.pro-list').css('marginTop','8.34rem');
	}
	
	$('body').on('click','.pro-list .mui-row',function(){
		var ids = $(this).attr('data-id');
		app.open('classroom.articleDetail.html','class_article',{id:ids,title:'疑难解答'},window.location.href,document.body.scrollTop);
	});
	
	$('body').on('click','.pro-search',function(){
		var ques = $('#ques').val();
		window.sessionStorage.setItem('pro-search',ques);
		app.ajax(
			'/Member/News/getting_started_list',
			{
				keyword : ques,
				classid : 26,
				page : 1
			},function(res){
				if(res.code == 200){
					if(res.list.length > 0){
						app.tpl($('.pro-list'),'tpl-pro-list',res);
					}else{
						$('.pro-list').html("<div class='tC promp-order' style='position:absolute;top:50%;left:15%;height:30%;width:70%;'><span class='cGrey fS13'>未搜索到 <span class='fS15'>"+ques+"</span> 相关的问题</span></div>");
					}
				}else{
					layer.msg('网络繁忙，请稍候再试');
				}
			}
		)
	});
	
	$(window).scroll(function(){
		echo.init();
		if($('.pro-list .mui-row').html()){
		// 当滚动到距底部以上200像素
		var offset = $(".pro-list").offset(),
		dataType = 0,
		data = {};
		var documentHeight = offset.top + $(".pro-list").height();
		if (documentHeight - $(this).scrollTop() - $(this).height()<100){
			var key = '';
				if(window.sessionStorage.getItem('pro-search')){
					key = window.sessionStorage.getItem('pro-search');
				}
				data = {
					page :pro_load_page,
					classid : 26,
					keyword : key
				};
			pro_load_flag && quesList.loadMore('/Member/News/getting_started_list',data);
		}
		}else{
			return false;
		}
	});
}
